package com.study.d012Components;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

/**
 * ButtonBar的使用
 *
 */
public class ButtonBarMain extends Application implements EventHandler<ActionEvent>{
	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage stage) throws Exception {

		stage.show();

		ButtonBar bar = new ButtonBar();
		Button b1 = new Button("button01");
		Button b2 = new Button("button02");
		Button b3 = new Button("button03");
		bar.getButtons().addAll(b1,b2,b3);

		ButtonBar.setButtonData(b1, ButtonData.APPLY);
		ButtonBar.setButtonData(b2, ButtonData.CANCEL_CLOSE);
		ButtonBar.setButtonData(b3, ButtonData.NO);

		//按组件的添加顺序排序
		bar.setButtonOrder(ButtonBar.BUTTON_ORDER_NONE);

		AnchorPane aPane = new AnchorPane();
		aPane.getChildren().add(bar);

		stage.setScene(new Scene(aPane,400,300));

		b1.setOnAction(this);
		b2.setOnAction(this);
		b3.setOnAction(this);

	}

	@Override
	public void handle(ActionEvent event) {
		Button button= (Button)event.getSource();
		if(ButtonBar.getButtonData(button)==ButtonData.APPLY){
			System.out.println("标签APPLY " + button.getText());
		}else if(ButtonBar.getButtonData(button)==ButtonData.CANCEL_CLOSE){
			System.out.println("标签CANCEL_CLOSE " + button.getText());
		}else if(ButtonBar.getButtonData(button)==ButtonData.NO){
			System.out.println("标签NO " + button.getText());
		}
	}


}
